<!doctype html>
<html class="x-admin-sm">

<head>
	<meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
	<title>宇成建筑</title>
	<link rel="stylesheet" href="../statics/css/font.css">
	<link rel="stylesheet" href="../statics/plugins/layui/css/layui.css">
	<link rel="stylesheet" href="../statics/css/xadmin.css">
	<link rel="stylesheet" href="../statics/css/style.css">
</head>
<body class="index">
	<!-- 顶部开始 -->
	<div class="container">
		<div class="logo">
			<a href="./index.html">
				宇成建筑
			</a>
		</div>
		<div class="left_open">
			<a><i title="展开左侧栏" class="iconfontBlod">&#xe6f1;</i></a>
		</div>
		<div class="index_center">
			君正方华建筑施工劳务企业管理系统
		</div>
		<ul class="layui-nav right" lay-filter="">
			<li class="layui-nav-item">
				<a href="javascript:;"><span class="username"></span>(<span class="projectName"></span>)</a>
				<dl class="layui-nav-child">
					<!-- 二级菜单 -->
					<dd>
						<a href='javascript:;' onclick="changePassword()">修改密码</a>
					</dd>
					<dd>
						<a onclick="layout()" href="./login.html">退出</a>
					</dd>
				</dl>
			</li>
		</ul>
	</div>
	<!-- 顶部结束 -->
	<!-- 中部开始 -->
	<!-- 左侧菜单开始 -->
	<div class="left-nav">
		<div id="side-nav">
			<ul id="nav">
				
			</ul>
		</div>
	</div>
	<!-- 左侧菜单结束 -->
	<!-- 右侧主体开始 -->
	<div class="page-content">
		<div class="layui-tab tab" lay-filter="xbs_tab" lay-allowclose="false">
<!--			<ul class="layui-tab-title">-->
<!--				<li class="home">-->
<!--					<i class="layui-icon">&#xe68e;</i>-->
<!--					我的桌面-->
<!--				</li>-->
<!--			</ul>-->
			<div class="layui-unselect layui-form-select layui-form-selected" id="tab_right">
				<dl>
					<dd data-type="this">关闭当前</dd>
					<dd data-type="other">关闭其它</dd>
					<dd data-type="all">关闭全部</dd>
				</dl>
			</div>
			<div class="layui-tab-content">
				<div class="layui-tab-item layui-show">
					<iframe src='./welcome.html' frameborder="0" scrolling="yes" class="x-iframe"></iframe>
				</div>
			</div>
			<div id="tab_show"></div>
		</div>
	</div>
	<div class="page-content-bg"></div>
	<!-- 右侧主体结束 -->
	<!-- 中部结束 -->
</body>
<script src='../statics/plugins/jQuery-3.2.1/jquery-3.2.1.min.js'></script>
<script src="../statics/plugins/layui/layui.js" charset="utf-8"></script>
<script src="../statics/plugins/X-admin/xadmin.js"></script>
<script src="../statics/js/public.js?v=1129"></script>
<script>
	var username = $.parseJSON(localStorage.getItem('login_msg')).name;
	var token = $.parseJSON(localStorage.getItem('login_msg')).accessToken;
	$('.projectName').html(getParam('projectName'));
	$('.username').html(username);
	var menu=$.parseJSON(localStorage.getItem('menu'));
	var ul='';
	for(var i=0;i<menu.length;i++){
		ul+=`
			<li class="layui-nav-item" auth='${menu[i].code}'>
				<a href="javascript:;">
					<i class="iconfontBlod left-nav-li " lay-tips="${menu[i].name}">&#xe783;</i>
					<cite>${menu[i].name}</cite>
					<i class="iconfontBlod nav_right">&#xe6fa;</i>
				</a>
				<ul class="sub-menu">`
		if(menu[i].children.length>0){
			for(var j=0;j<menu[i].children.length;j++){
				ul+=`
					<li>
						<a onclick="xadmin.iframe('${menu[i].children[j].name}','${menu[i].children[j].url}')" auth='${menu[i].children[j].code}'>
							<i class="iconfontBlod">&#xe6ed;</i>
							<cite>${menu[i].children[j].name}</cite>
						</a>
					</li>
				`
			}
		}
			ul+=`</ul>
			</li>
		`
	}
	$('#nav').html(ul);
	permission();
	/*
	 * 新密码格式提示
	 */
	$('body').on('focus', 'input[name="newPwd"]', function () {
		$(this).prev().css('color', '#666');
		$(this).prev().html('只能输入8-16位,包含数字和字母的密码');
	})
	/*
	 * 验证密码正则
	 */
	var reg = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,16}$/;
	/*
	 * 修改密码
	 */
	$('body').on('blur', 'input[name="newPwd"]', function () {
		switch (reg.test($(this).val())) {
			case true:
				$(this).prev().html("");
				break;
			default:
				$(this).prev().css('color', 'red');
				$(this).prev().html("新密码格式不正确!");
				break;
		}
	})
	/*
	 * 确认密码
	 */
	$('body').on('blur', 'input[name="confirmPwd"]', function () {
		switch ($(this).val()) {
			case $('input[name="newPwd"]').val():
				$(this).prev().html("");
				break;
			default:
				$(this).prev().css('color', 'red');
				$(this).prev().html("确认密码与新密码不一致!");
				break;
		}
	})
	/*
	 * 修改密码
	 */
	function changePassword() {
		layui.use('layer', function () {
			var layer = layui.layer;
			layer.open({
				type: 1,
				title: '修改密码',
				area: ['40rem', '20rem'],
				btn: ['确认', '取消'],
				content: `
                    <form class="layui-form changePassword" action="">
                        <div class="layui-form-item" style="margin-top: 20px;">
                            <label class="layui-form-label">修改密码</label>
                            <div class="layui-input-block">
                                <b></b>
                                <input type='password' placeholder='请输入新密码' name='newPwd' class="layui-input" style="display: inline-block">

                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">确认密码</label>
                            <div class="layui-input-block">
                                <b></b>
                                <input type='password' placeholder='请确认新密码' name='confirmPwd' class="layui-input" style="display: inline-block">

                            </div>
                        </div>
                    </form>
                `,
				yes: function () {
					var adminId=Number($.parseJSON(localStorage.getItem('login_msg')).id);
					var password = $('input[name="newPwd"]').val();
					var confirmPassword = $('input[name="confirmPwd"]').val();
					$.ajax({
						url:url+'/auth/auth/changePwd',
						type:'post',
						data:{
							adminId:adminId,
							password:password,
							confirmPwd:confirmPassword,
							token:$.parseJSON(localStorage.getItem('login_msg')).token
						},
						dataType:'json',
						success:function(r){
							if(r.code==100000){
								tips('修改密码', r);
								setTimeout(function () {
									window.location.reload()
								}, 2000)
							}else{
								tips('修改密码', r);
							}
						}
					})
				}
			});
		});
	}

	/*
	 * 退出
	 */
	function layout() {
		$.ajax({
			url: url + "/auth/logout",
			type: "POST",
			data: {},
			success:function(r){
				localStorage.clear();
				window.top.location='login.html';
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {
				localStorage.clear();
				window.top.location='login.html';
			}
		})
	}
</script>

</html>